import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CinemaSystem extends JFrame {



    public CinemaSystem(){
//        User.setUserMap("1","1","管理员","2022-01-01","12345678901");
//        User.setUserMap("2","2","经理","2022-01-01","23456789011");
//        User.setUserMap("3","3","前台","2022-01-01","34567890112");
//        User.setUserMap("4","123456","前台","2022-01-01","45678901123");
//
//        Film.addFilm("1","2","3","------------------------------------------------------------------------------------------","NAN分钟","0.0","未上映");
//
        Cinema.setCinemaRoom("黄金厅",8,10);
        Cinema.setCinemaRoom("白银厅",10,12);
        Cinema.setCinemaRoom("翡翠厅",7,8);
        Cinema.setCinemaRoom("钻石厅",7,8);
        Cinema.setCinemaRoom("宝石厅",8,9);
//        Cinema.setCinemaRoom("1",8,9);


        User.setUserMap("admin","ynuinfo#777","管理员","1949-10-01","00000000000");


        Font loginFont = new Font("SimSun",Font.BOLD, 15); // 创建一个字体对象，设置字体、样式和大小
        //---------------------
        JButton login = new JButton("登录");
        login.setPreferredSize(new Dimension(120, 60)); // 设置按钮的首选大小
        login.setFont(loginFont); // 设置按钮的字体
        //---------------------
        JButton admin = new JButton("管理员功能");
        admin.setPreferredSize(new Dimension(120, 60));
        admin.setFont(loginFont);
        //---------------------
        JButton manager = new JButton("经理功能");
        manager.setPreferredSize(new Dimension(120, 60));
        manager.setFont(loginFont);
        //---------------------
        JButton frontdesk = new JButton("前台功能");
        frontdesk.setPreferredSize(new Dimension(120, 60));
        frontdesk.setFont(loginFont);
        //---------------------
        JButton exit = new JButton("退出");
        exit.setPreferredSize(new Dimension(120, 60));
        exit.setFont(loginFont);

        setVisible(true);
        setTitle("影院管理系统");
        setBounds(480,270,480,270);
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        c.add(login);
        c.add(admin);
        c.add(manager);
        c.add(frontdesk);
        c.add(exit);


        login.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(User.nowUser == null) {
                    LogIn login = new LogIn(CinemaSystem.this);
                    login.setVisible(true);
                }else{
                    JOptionPane.showMessageDialog(null,"您已经登录，请先退出登录");
                }
            }
        });

        admin.addActionListener(new ActionListener() {
            @Override

            public void actionPerformed(ActionEvent e) {
                if(User.nowUser == null){
                    JOptionPane.showMessageDialog(null,"请先登录");
                }
                else if(User.getUserMap().get(User.nowUser).get(1).equals("管理员")) {
                    Admin admin = new Admin(CinemaSystem.this);
                    admin.setVisible(true);
                }
                else{
                    JOptionPane.showMessageDialog(null,"您不是管理员，无法进入管理员功能！");
                }
            }
        });

        manager.addActionListener(new ActionListener() {
            @Override

            public void actionPerformed(ActionEvent e) {
                if(User.nowUser == null){
                    JOptionPane.showMessageDialog(null,"请先登录");
                }
                else if(User.getUserMap().get(User.nowUser).get(1).equals("经理")) {
                    Manager manager = new Manager(CinemaSystem.this);
                    manager.setVisible(true);
                }
                else{
                    JOptionPane.showMessageDialog(null,"您不是经理，无法进入经理功能！");
                }
            }
        });

        frontdesk.addActionListener(new ActionListener() {
            @Override

            public void actionPerformed(ActionEvent e) {
                if(User.nowUser == null){
                    JOptionPane.showMessageDialog(null,"请先登录");
                }
                else if(User.getUserMap().get(User.nowUser).get(1).equals("前台")) {
                    FrontDesk frontDesk = new FrontDesk(CinemaSystem.this);
                    frontDesk.setVisible(true);
                }
                else{
                    JOptionPane.showMessageDialog(null,"您不是前台，无法进入前台功能！");
                }
            }
        });

        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
}
